package cfengMiddleware.server.springEventDriven.event;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.context.ApplicationEvent;

import java.io.Serializable;

/**
 * @author Cfeng
 * @date 2022/9/15
 * 演示传统的Spring事件驱动
 * 封装登录成功的消息实体LoginEvent： 包括登录用户名，时间、IP
 */

@Getter
@Setter
@ToString
public class LoginEvent extends ApplicationEvent implements Serializable {

    private static final long serialVersionUID = 2620840985270980987L;

    private String userName;

    private String logTime;

    private String ip; //登陆IP

    //需要重写构造方法
    public LoginEvent(Object source) {
        super(source);
    }

    //这里的source就相当于之前的普通的消息的发送者，事件源、生产者， 就像公共聊天： 生产者和Data
    public LoginEvent(Object source, String userName, String logTime, String ip) {
        super(source);
        this.userName = userName;
        this.logTime = logTime;
        this.ip = ip;
    }
}
